package com.bootx.controller.api;

import com.bootx.common.Result;
import com.bootx.controller.BaseController;
import com.bootx.entity.AiRole;
import com.bootx.service.AiRoleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/config")
public class ConfigController extends BaseController {

    private final AiRoleService aiRoleService;

    public ConfigController(AiRoleService aiRoleService) {
        super();
        this.aiRoleService = aiRoleService;
    }

    @PostMapping("/home")
    public Result home(){
        Map<String,Object> map = new HashMap<>();
        map.put("appName","灵写AI");
        map.put("welcomeTitle","欢迎来到灵写AI");
        map.put("image1","icon_creater.png");
        map.put("image2","icon_home_aippt.png");
        map.put("image3","icon_original.png");
        List<Map<String,Object>> list1 = new ArrayList<>();
        list1.add(Map.of("id",1,"name","图文创作","tag","icon_home_hot.png","icon","icon_home_twcz.png"));
        list1.add(Map.of("id",2,"name","长文本写作","tag","icon_home_new.png","icon","icon_home_cwbxz.png"));
        list1.add(Map.of("id",3,"name","文本纠错","icon","icon_home_wbjc.png"));
        list1.add(Map.of("id",4,"name","公文写作","icon","icon_home_gwxz.png"));
        list1.add(Map.of("id",5,"name","文案提取","icon","icon_home_watq.png"));
        map.put("list1",list1);
        List<Map<String, Object>> list2 = jdbcTemplate.queryForList("select id,name from write_tool_category where type='home'");
        list2.forEach(item -> {
            item.put("list",jdbcTemplate.queryForList("select id,name,icon,memo,type from write_tool where id in (select write_tools_id from write_tool_write_tool_categories where write_tool_categories_id =?)",item.get("id")));
        });
        map.put("list2",list2);
        return Result.success(map);
    }

    @PostMapping("/create")
    public Result create(){
        Map<String,Object> map = new HashMap<>();
        List<Map<String,Object>> list1 = new ArrayList<>();
        list1.add(Map.of("name","论文类","icon","icon_creater_paper.png","id",1));
        list1.add(Map.of("name","职场类","icon","icon_creater_workplace.png","id",2));
        list1.add(Map.of("name","新媒体","icon","icon_creater_media.png","id",3));
        list1.add(Map.of("name","短视频","icon","icon_creater_video.png","id",4));
        list1.add(Map.of("name","公文类","icon","icon_creater_doc.png","id",5));
        list1.add(Map.of("name","作文类","icon","icon_creater_write.png","id",6));
        list1.add(Map.of("name","小说类","icon","icon_creater_novel.png","id",7));
        list1.add(Map.of("name","诗词歌赋","icon","icon_creater_poetry.png","id",8));
        map.put("list1",list1);
        List<Map<String, Object>> list2 = jdbcTemplate.queryForList("select id,name from write_tool_category where type='create'");
        list2.forEach(item -> {
            item.put("list",jdbcTemplate.queryForList("select id,name,icon,memo,type from write_tool where id in (select write_tools_id from write_tool_write_tool_categories where write_tool_categories_id =?)",item.get("id")));
        });
        map.put("list2",list2);
        return Result.success(map);
    }

    @PostMapping("/work")
    public Result work(){
        Map<String,Object> map = new HashMap<>();
        List<Map<String, Object>> list2 = jdbcTemplate.queryForList("select id,name from write_tool_category where type='work'");
        list2.forEach(item -> {
            item.put("list",jdbcTemplate.queryForList("select id,name,icon,memo,type from write_tool where id in (select write_tools_id from write_tool_write_tool_categories where write_tool_categories_id =?)",item.get("id")));
        });
        map.put("list2",list2);
        return Result.success(map);
    }



    @PostMapping("/ai")
    public Result ai(){
        Map<String,Object> map = new HashMap<>();

        AiRole aiRole = aiRoleService.find(59L);
        aiRole.getExamples().add("请问诺贝尔奖的是怎么来的?");
        aiRole.getExamples().add("你知道中国GDP排名前十的城市是哪些吗?");
        aiRole.getExamples().add("你知道人的智商有哪些划分标准吗");
        aiRoleService.update(aiRole);
        map.put("id",aiRole.getId());
        map.put("firstName",aiRole.getName());
        map.put("memo",aiRole.getMemo());
        map.put("list1",aiRole.getExamples());
        List<Map<String, Object>> list2 = jdbcTemplate.queryForList("select id,name,memo,avatar from ai_role where type=0;");
        map.put("list2",list2);
        return Result.success(map);
    }

}
